package com.duan.boot.config;

import com.duan.boot.interceptor.UserLoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author duan
 * @date 2022/12/1 19:56
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Bean
    public UserLoginInterceptor userLoginInterceptor(){
        return new UserLoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> paths = new ArrayList<>();

        paths.add("/swagger/**");
        paths.add("/v2/api-docs");
        paths.add("/swagger-ui.html");
        paths.add("/swagger-resources/**");
        paths.add("/doc.html");
        paths.add("/v1/oa/User/Login");
        registry.addInterceptor(userLoginInterceptor()).addPathPatterns("/**")
                .excludePathPatterns(paths);
    }
}

